import sys
import os

import word_helper

base_url='https://dict.hjenglish.com/jp/jc/'





def start(arg_list):
    print('正在读取单词列表.....')
    fx_list=word_helper.get_fx_list()
    len_fx_list=len(fx_list)
    print('over')
    if fx_list==[]:
        print('现在无复习单词')

    for i in range(len_fx_list):
        print('剩余%d个单词待复习'%(len_fx_list-i))
        word=fx_list[i]
        word=word_helper.get_word_in_net(base_url+word['word_text'],word=word)
        word_helper.show_front(word)
        list=get_command()
        if list[0]=='s':
            word_helper.show_word_all(word)
            list=get_command()
            if list[0] == 'h':
                word['next_time'] = word_helper.add_time_by_hour(word['update_time'], list[1])
                word_helper.update(word)
                print('success')
            if list[0].isdigit():
                word['next_time'] = word_helper.add_time_by_hour(word['update_time'], list[0])
                word_helper.update(word)
                print('success')
            if list[0] == 'd':
                word['next_time'] = word_helper.add_time_by_day(word['update_time'], list[1])
                word_helper.update(word)
                print('success')
            if i + 1 == len(fx_list):
                print('现在无复习单词')
                break
            continue

        if list[0]=='h':
            word['next_time']=word_helper.add_time_by_hour(word['update_time'],list[1])
            word_helper.update(word)
            print('success')
        if list[0].isdigit():
            word['next_time'] = word_helper.add_time_by_hour(word['update_time'], list[0])
            word_helper.update(word)
            print('success')
        if list[0]=='d':
            word['next_time'] = word_helper.add_time_by_day(word['update_time'], list[1])
            word_helper.update(word)
            print('success')
        if i + 1 == len(fx_list):
            print('现在无复习单词')
            break


def clear(arg_list):
     if os.name == 'posix':
         os.system('clear')
     elif os.name == 'nt':
         os.system('cls')
     else:
         import curses
         curses.setupterm()
         lines = curses.tigetnum('lines')
         for x in range(lines):
             print
         print ('\x1b[H\x1b2J')



'''
调用添加单词
'''
def add(arg_list):
    word_text=arg_list[0]
    word_helper.add_new_word(word_text)
    print('添加单词成功')

def show(arg_list):
    word_text=arg_list[0]
    word=word_helper.load_word(word_text)
    word_helper.show_word_all(word)


def get_command():
	str=input()
	list=str.split(' ')
	return list

def function_callder(name='start',arg_list=[]):
    eval(name)(arg_list)







'''
入口
'''
def index():
    print('欢迎回来\n')
    while 1:
        list = get_command()
        if list[0]=='exit':
            print('再见')
            break
        function_callder(list[0], list[1:])

index()



